import { defineComponent, ref } from 'vue'
import {
  NButton,
  NDataTable,
  NDatePicker,
  NIcon,
  NInput,
  NPagination,
  NSpace
} from 'naive-ui'
import { SearchOutlined } from '@vicons/antd'
import Card from '@/components/card'
import { useColumns } from './use-columns'
import { useTable } from './use-table'
import LogModal from '@/components/log-modal'

const TmpExecRecordFooter = defineComponent({
  name: 'TmpExecRecordFooter',
  props: {
    taskDefinedId: {
      type: Number,
      required: true
    }
  },
  setup() {
    const { state, updateList, changePage, changePageSize, onOperationClick } =
      useTable()
    const { columnsRef } = useColumns(onOperationClick)

    return {
      state,
      columnsRef,
      onUpdatedList: updateList,
      changePage,
      changePageSize
    }
  },
  mounted() {
    this.state.taskDefinedId = this.taskDefinedId
    this.onUpdatedList()
  },
  render() {
    return (
      <>
        <div>
          <Card>
            <NSpace justify='end'>
              <NSpace>
                <NInput
                  v-model:value={this.state.searchParam.username}
                  clearable
                  size='small'
                  style='width: 150px'
                  placeholder={window.$t('taskManage.execUser')}
                />
                <NDatePicker
                  type='datetimerange'
                  size='small'
                  clearable
                  v-model:value={this.state.searchParam.startEndTime}
                />
                <NButton type='info' size='small' onClick={this.onUpdatedList}>
                  <NIcon>
                    <SearchOutlined />
                  </NIcon>
                </NButton>
              </NSpace>
            </NSpace>
          </Card>
          <Card>
            <NSpace vertical>
              <NDataTable
                row-class-name='items'
                columns={this.columnsRef.columns}
                size='small'
                data={this.state.list}
                loading={this.state.loading}
                scrollX={this.columnsRef.tableWidth}
              />
              <NSpace justify='end'>
                <NPagination
                  v-model:page={this.state.page}
                  v-model:page-size={this.state.limit}
                  item-count={this.state.count}
                  show-size-picker
                  page-sizes={[10, 30, 50]}
                  show-quick-jumper
                  on-update:page={this.changePage}
                  on-update:page-size={this.changePageSize}
                />
              </NSpace>
            </NSpace>
          </Card>
        </div>
        <LogModal
          showModalRef={this.state.showViewLogModal}
          onConfirmModal={() => {
            this.state.showViewLogModal = false
          }}
          taskInstanceId={this.state.currentRecord.id}
        />
      </>
    )
  }
})

export default TmpExecRecordFooter
